package com.example.dirviesystem.repository;

import com.example.dirviesystem.entity.StudentInfo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface StudentInfoRe extends JpaRepository<StudentInfo, Long>, JpaSpecificationExecutor<StudentInfo> {
   StudentInfo findByAndIdNumberAndPassword(String username, String password);

   List<StudentInfo> findAllByCoachId(Long coachId); // 根据教练 ID 查询学员信息

   @Query("SELECT s FROM StudentInfo s WHERE s.coach.id = :coachId AND (:name IS NULL OR s.name LIKE %:name%)")
   Page<StudentInfo> findAllByCoachIdAndName(
           @Param("coachId") Long coachId,
           @Param("name") String name,
           Pageable pageable);
}

